package org.lanyu.springainovel.common.entity;

import java.time.Duration;
import java.util.List;
import java.util.Map;

/**
 * 服务器配置类
 */
public class ServerConfig {
    public ServerConfig() { super(); }
    private String name;
    private String url;
    private String sseEndpoint; // SSE端点，默认为/sse
    private Map<String, String> headers;
    private Duration timeout = Duration.ofSeconds(30);
    private boolean enabled = true;
    
    // NPX相关配置
    private String command; // 主命令，如npx
    private List<String> args; // 参数列表
    private Map<String, String> env; // 环境变量
    private String workingDirectory; // 工作目录

    // Getters and Setters
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public String getUrl() { return url; }
    public void setUrl(String url) { this.url = url; }

    public String getSseEndpoint() { return sseEndpoint; }
    public void setSseEndpoint(String sseEndpoint) { this.sseEndpoint = sseEndpoint; }

    public Map<String, String> getHeaders() { return headers; }
    public void setHeaders(Map<String, String> headers) { this.headers = headers; }

    public Duration getTimeout() { return timeout; }
    public void setTimeout(Duration timeout) { this.timeout = timeout; }

    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }

    /**
     * 获取完整的SSE URL（基础URL + SSE端点�?     */
    public String getFullSseUrl() {
        if (url == null) return null;
        if (url.startsWith("stdio://")) return url;

        String baseUrl = url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
        String endpoint = sseEndpoint.startsWith("/") ? sseEndpoint : "/" + sseEndpoint;
        return baseUrl + endpoint;
    }

    // NPX相关Getter和Setter方法
    public String getCommand() { return command; }
    public void setCommand(String command) { this.command = command; }

    public List<String> getArgs() { return args; }
    public void setArgs(List<String> args) { this.args = args; }

    public Map<String, String> getEnv() { return env; }
    public void setEnv(Map<String, String> env) { this.env = env; }

    public String getWorkingDirectory() { return workingDirectory; }
    public void setWorkingDirectory(String workingDirectory) { this.workingDirectory = workingDirectory; }

    /**
     * 判断是否为NPX类型
     */
    public boolean isNpxType() {
        return "npx".equalsIgnoreCase(command) || (url != null && url.startsWith("npx://"));
    }
}
